#ifndef NET_H
#define NET_H

#include <sys/types.h>
#include <netinet/in.h>

#include "queue.h"

struct flow;
typedef struct flowset {
  /* list of flows sorted in time order */
  TAILQ_HEAD(,flow) flows;
  int n_flows;
  TAILQ_HEAD(,packet) packets;
  int n_packets;
} flowset_t;

flowset_t *flowset_load(const char *, const char *);

typedef enum {
  DIALOG_FLOW,	/* contains REQUEST and RESPONSE */
  MONOLOG_FLOW,	/* contains no REQUEST or no RESPONSE */
} flow_type_e;

typedef enum {
  UNKNOWN = 0,		/* -ieth and loopback */
  UNICAST_TO_US,	/* used in -iany capture */
  SENT_BY_US,
} flow_role_e;

struct packet;
typedef struct flow {
  /* identification */
  struct timeval when;
  /* from target or not */
  flow_role_e role;
  /* l3/l4 information */
  struct sockaddr_in connector, connectee;
  int protocol;
  /* dialog or monolog */
  flow_type_e type;
  enum packet_type *last_packet;
  /* list of packets sorted in time order */
  TAILQ_HEAD(,packet) packets;
  TAILQ_ENTRY(flow) next;
} flow_t;

typedef enum packet_type {
  REQUEST_PACKET,
  RESPONSE_PACKET,
} packet_type_e;

typedef struct packet {
  /* identification */
  struct timeval when;
  packet_type_e type;
  struct iovec segment;
  flow_t *flow;
  TAILQ_ENTRY(packet) next_by_flow;
  TAILQ_ENTRY(packet) next_by_time;
} packet_t;

#endif /* NET_H */
